﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using RTGS.Library.Entities.Rtgs;
using RTGS.Library.DataAccess.Rtgs;
using System.Configuration;

namespace RTGS.Web.form.rtgs
{

public partial class form_rtgs_rule_mt : BasePage
    {
        private string id = string.Empty;

        private  stpRuleMtRepo trnDal = new stpRuleMtRepo(ConfigurationManager.ConnectionStrings["Rtgs"].ConnectionString);

        private  stpMtRepo stpMtrepo = new stpMtRepo(ConfigurationManager.ConnectionStrings["Rtgs"].ConnectionString);
        private stpRuleRepo stpRulerepo = new stpRuleRepo(ConfigurationManager.ConnectionStrings["Rtgs"].ConnectionString);


        protected void Page_Load(object sender, EventArgs e)
        {

            List<stpMt> liststpMt = stpMtrepo.GetList();
            foreach (var item in liststpMt)
            {
                ddlMt.Items.Add(new ListItem(item.mtcode+" - "+item.mtdesc, item.mtcode));
            }

            ddlMt.Items.Insert(0, new ListItem("---Pilih Data---", string.Empty));


            List<stpRule> listsRule = stpRulerepo.GetList();
            foreach (var item in listsRule)
            {
                ddlRule.Items.Add(new ListItem(item.rulecode + " - " + item.ruledesc, item.rulecode));
            }

            ddlRule.Items.Insert(0, new ListItem("---Pilih Data---", string.Empty));

            if (Request.Params["id"] != null)
            {
                id = Convert.ToString(Request.Params["id"]);
            }

            if (!Page.IsPostBack)
            {
                if (id.Trim().Length > 0) // Edit an existing item
                {
                    stpRuleMt obj = trnDal.GetById(Convert.ToInt32(id));
                    if (obj != null)
                    {
                        hfID.Value = id.ToString();
                       
                        ddlMt.Items.FindByValue(obj.ruleMtmtcode).Selected = true;
                        ddlRule.Items.FindByValue(obj.ruleMtrulecode).Selected = true;
                       
                        
                    }
                }
            }

        }

    }
}